<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>mainwindow.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-widgets-charactermap-example.html">Character Map Example</a></td><td >mainwindow.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">mainwindow.cpp 示例文件</h1>
<span class="subtitle">widgets/charactermap/mainwindow.cpp</span>
<!-- $$$widgets/charactermap/mainwindow.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &lt;QtWidgets&gt;</span>

  <span class="preprocessor">#include &quot;characterwidget.h&quot;</span>
  <span class="preprocessor">#include &quot;mainwindow.h&quot;</span>


  Q_DECLARE_METATYPE(<span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>FontFilter)

  MainWindow<span class="operator">::</span>MainWindow()
  {
      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>fileMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;File&quot;</span>));
      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;Quit&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qwidget.html">QWidget</a></span><span class="operator">::</span>close);
      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>helpMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;&amp;Help&quot;</span>));
      helpMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;Show Font Info&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>showInfo);
      helpMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;About &amp;Qt&quot;</span>)<span class="operator">,</span> <a href="qapplication.html#qApp">qApp</a><span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>aboutQt);

      <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>centralWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>filterLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Filter:&quot;</span>));
      filterCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
      filterCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;All&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(<span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>AllFonts));
      filterCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Scalable&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(<span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>ScalableFonts));
      filterCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Monospaced&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(<span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>MonospacedFonts));
      filterCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Proportional&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(<span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>ProportionalFonts));
      filterCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(<span class="number">0</span>);
      connect(filterCombo<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="type">int</span><span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qcombobox.html">QComboBox</a></span><span class="operator">::</span>currentIndexChanged)<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>filterChanged);

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>fontLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Font:&quot;</span>));
      fontCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span>;
      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>sizeLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Size:&quot;</span>));
      sizeCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>styleLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Style:&quot;</span>));
      styleCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>fontMergingLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Automatic Font Merging:&quot;</span>));
      fontMerging <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcheckbox.html">QCheckBox</a></span>;
      fontMerging<span class="operator">-</span><span class="operator">&gt;</span>setChecked(<span class="keyword">true</span>);

      scrollArea <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qscrollarea.html">QScrollArea</a></span>;
      characterWidget <span class="operator">=</span> <span class="keyword">new</span> CharacterWidget;
      scrollArea<span class="operator">-</span><span class="operator">&gt;</span>setWidget(characterWidget);

      findStyles(fontCombo<span class="operator">-</span><span class="operator">&gt;</span>currentFont());
      findSizes(fontCombo<span class="operator">-</span><span class="operator">&gt;</span>currentFont());

      lineEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>;
      lineEdit<span class="operator">-</span><span class="operator">&gt;</span>setClearButtonEnabled(<span class="keyword">true</span>);
  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>clipboardButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">&quot;&amp;To clipboard&quot;</span>));

  <span class="preprocessor">#endif</span>

      connect(fontCombo<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>currentFontChanged<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>findStyles);
      connect(fontCombo<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>currentFontChanged<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>findSizes);
      connect(fontCombo<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>currentFontChanged<span class="operator">,</span>
              characterWidget<span class="operator">,</span> <span class="operator">&amp;</span>CharacterWidget<span class="operator">::</span>updateFont);
      connect(sizeCombo<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span><span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qcombobox.html">QComboBox</a></span><span class="operator">::</span>currentIndexChanged)<span class="operator">,</span>
              characterWidget<span class="operator">,</span> <span class="operator">&amp;</span>CharacterWidget<span class="operator">::</span>updateSize);
      connect(styleCombo<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span><span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qcombobox.html">QComboBox</a></span><span class="operator">::</span>currentIndexChanged)<span class="operator">,</span>
              characterWidget<span class="operator">,</span> <span class="operator">&amp;</span>CharacterWidget<span class="operator">::</span>updateStyle);
      connect(characterWidget<span class="operator">,</span> <span class="operator">&amp;</span>CharacterWidget<span class="operator">::</span>characterSelected<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>insertCharacter);

  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      connect(clipboardButton<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>updateClipboard);
  <span class="preprocessor">#endif</span>
      connect(fontMerging<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>toggled<span class="operator">,</span> characterWidget<span class="operator">,</span> <span class="operator">&amp;</span>CharacterWidget<span class="operator">::</span>updateFontMerging);

      <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>controlsLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>;
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(filterLabel);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(filterCombo<span class="operator">,</span> <span class="number">1</span>);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontLabel);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontCombo<span class="operator">,</span> <span class="number">1</span>);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(sizeLabel);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(sizeCombo<span class="operator">,</span> <span class="number">1</span>);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(styleLabel);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(styleCombo<span class="operator">,</span> <span class="number">1</span>);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontMergingLabel);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontMerging<span class="operator">,</span> <span class="number">1</span>);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addStretch(<span class="number">1</span>);

      <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>lineLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>;
      lineLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(lineEdit<span class="operator">,</span> <span class="number">1</span>);
      lineLayout<span class="operator">-</span><span class="operator">&gt;</span>addSpacing(<span class="number">12</span>);
  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      lineLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(clipboardButton);
  <span class="preprocessor">#endif</span>

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>centralLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>;
      centralLayout<span class="operator">-</span><span class="operator">&gt;</span>addLayout(controlsLayout);
      centralLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(scrollArea<span class="operator">,</span> <span class="number">1</span>);
      centralLayout<span class="operator">-</span><span class="operator">&gt;</span>addSpacing(<span class="number">4</span>);
      centralLayout<span class="operator">-</span><span class="operator">&gt;</span>addLayout(lineLayout);
      centralWidget<span class="operator">-</span><span class="operator">&gt;</span>setLayout(centralLayout);

      setCentralWidget(centralWidget);
      setWindowTitle(tr(<span class="string">&quot;Character Map&quot;</span>));
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>findStyles(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> <span class="operator">&amp;</span>font)
  {
      <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span> fontDatabase;
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> currentItem <span class="operator">=</span> styleCombo<span class="operator">-</span><span class="operator">&gt;</span>currentText();
      styleCombo<span class="operator">-</span><span class="operator">&gt;</span>clear();

      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> style;
      foreach (style<span class="operator">,</span> fontDatabase<span class="operator">.</span>styles(font<span class="operator">.</span>family()))
          styleCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(style);

      <span class="type">int</span> styleIndex <span class="operator">=</span> styleCombo<span class="operator">-</span><span class="operator">&gt;</span>findText(currentItem);

      <span class="keyword">if</span> (styleIndex <span class="operator">=</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>)
          styleCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(<span class="number">0</span>);
      <span class="keyword">else</span>
          styleCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(styleIndex);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>filterChanged(<span class="type">int</span> f)
  {
      <span class="keyword">const</span> <span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>FontFilter filter <span class="operator">=</span>
          filterCombo<span class="operator">-</span><span class="operator">&gt;</span>itemData(f)<span class="operator">.</span>value<span class="operator">&lt;</span><span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>FontFilter<span class="operator">&gt;</span>();
      fontCombo<span class="operator">-</span><span class="operator">&gt;</span>setFontFilters(filter);
      statusBar()<span class="operator">-</span><span class="operator">&gt;</span>showMessage(tr(<span class="string">&quot;%n font(s) found&quot;</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> fontCombo<span class="operator">-</span><span class="operator">&gt;</span>count()));
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>findSizes(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> <span class="operator">&amp;</span>font)
  {
      <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span> fontDatabase;
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> currentSize <span class="operator">=</span> sizeCombo<span class="operator">-</span><span class="operator">&gt;</span>currentText();

      {
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qsignalblocker.html">QSignalBlocker</a></span> blocker(sizeCombo);
          <span class="comment">// sizeCombo signals are now blocked until end of scope</span>
          sizeCombo<span class="operator">-</span><span class="operator">&gt;</span>clear();

          <span class="type">int</span> size;
          <span class="keyword">if</span> (fontDatabase<span class="operator">.</span>isSmoothlyScalable(font<span class="operator">.</span>family()<span class="operator">,</span> fontDatabase<span class="operator">.</span>styleString(font))) {
              foreach (size<span class="operator">,</span> <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>standardSizes()) {
                  sizeCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span>(size)<span class="operator">.</span>toString());
                  sizeCombo<span class="operator">-</span><span class="operator">&gt;</span>setEditable(<span class="keyword">true</span>);
              }

          } <span class="keyword">else</span> {
              foreach (size<span class="operator">,</span> fontDatabase<span class="operator">.</span>smoothSizes(font<span class="operator">.</span>family()<span class="operator">,</span> fontDatabase<span class="operator">.</span>styleString(font))) {
                  sizeCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span>(size)<span class="operator">.</span>toString());
                  sizeCombo<span class="operator">-</span><span class="operator">&gt;</span>setEditable(<span class="keyword">false</span>);
              }
          }
      }

      <span class="type">int</span> sizeIndex <span class="operator">=</span> sizeCombo<span class="operator">-</span><span class="operator">&gt;</span>findText(currentSize);

      <span class="keyword">if</span>(sizeIndex <span class="operator">=</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>)
          sizeCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(<a href="../qtcore/qtglobal.html#qMax">qMax</a>(<span class="number">0</span><span class="operator">,</span> sizeCombo<span class="operator">-</span><span class="operator">&gt;</span>count() <span class="operator">/</span> <span class="number">3</span>));
      <span class="keyword">else</span>
          sizeCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(sizeIndex);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>insertCharacter(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>character)
  {
      lineEdit<span class="operator">-</span><span class="operator">&gt;</span>insert(character);
  }

  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
  <span class="type">void</span> MainWindow<span class="operator">::</span>updateClipboard()
  {
      <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>clipboard()<span class="operator">-</span><span class="operator">&gt;</span>setText(lineEdit<span class="operator">-</span><span class="operator">&gt;</span>text()<span class="operator">,</span> <span class="type"><a href="../qtgui/qclipboard.html">QClipboard</a></span><span class="operator">::</span>Clipboard);
      <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>clipboard()<span class="operator">-</span><span class="operator">&gt;</span>setText(lineEdit<span class="operator">-</span><span class="operator">&gt;</span>text()<span class="operator">,</span> <span class="type"><a href="../qtgui/qclipboard.html">QClipboard</a></span><span class="operator">::</span>Selection);
  }
  <span class="preprocessor">#endif</span>

  <span class="keyword">class</span> FontInfoDialog : <span class="keyword">public</span> <span class="type"><a href="qdialog.html">QDialog</a></span>
  {
  <span class="keyword">public</span>:
      <span class="keyword">explicit</span> FontInfoDialog(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent <span class="operator">=</span> nullptr);

  <span class="keyword">private</span>:
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> text() <span class="keyword">const</span>;
  };

  FontInfoDialog<span class="operator">::</span>FontInfoDialog(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent) : <span class="type"><a href="qdialog.html">QDialog</a></span>(parent)
  {
      setWindowFlags(windowFlags() <span class="operator">&amp;</span> <span class="operator">~</span><span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>WindowContextHelpButtonHint);
      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>mainLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(<span class="keyword">this</span>);
      <span class="type"><a href="qplaintextedit.html">QPlainTextEdit</a></span> <span class="operator">*</span>textEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qplaintextedit.html">QPlainTextEdit</a></span>(text()<span class="operator">,</span> <span class="keyword">this</span>);
      textEdit<span class="operator">-</span><span class="operator">&gt;</span>setReadOnly(<span class="keyword">true</span>);
      textEdit<span class="operator">-</span><span class="operator">&gt;</span>setFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>systemFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>FixedFont));
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(textEdit);
      <span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span> <span class="operator">*</span>buttonBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span>(<span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span><span class="operator">::</span>Close<span class="operator">,</span> <span class="keyword">this</span>);
      connect(buttonBox<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span><span class="operator">::</span>rejected<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qdialog.html">QDialog</a></span><span class="operator">::</span>reject);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(buttonBox);
  }

  <span class="type"><a href="../qtcore/qstring.html">QString</a></span> FontInfoDialog<span class="operator">::</span>text() <span class="keyword">const</span>
  {
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> text;
      <span class="type"><a href="../qtcore/qtextstream.html">QTextStream</a></span> str(<span class="operator">&amp;</span>text);
      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> defaultFont <span class="operator">=</span> <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>systemFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>GeneralFont);
      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> fixedFont <span class="operator">=</span> <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>systemFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>FixedFont);
      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> titleFont <span class="operator">=</span> <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>systemFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>TitleFont);
      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> smallestReadableFont <span class="operator">=</span> <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>systemFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>SmallestReadableFont);

      str <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Qt &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> QT_VERSION_STR <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot; on &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>platformName()
          <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> logicalDpiX() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;DPI&quot;</span>;
      <span class="keyword">if</span> (<span class="operator">!</span><a href="../qtcore/qtglobal.html#qFuzzyCompare">qFuzzyCompare</a>(devicePixelRatioF()<span class="operator">,</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">1</span>)))
          str  <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, device pixel ratio: &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> devicePixelRatioF();
      str <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\n\nDefault font : &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> defaultFont<span class="operator">.</span>family() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> defaultFont<span class="operator">.</span>pointSizeF() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;pt\n&quot;</span>
          <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Fixed font   : &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> fixedFont<span class="operator">.</span>family() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> fixedFont<span class="operator">.</span>pointSizeF() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;pt\n&quot;</span>
          <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Title font   : &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> titleFont<span class="operator">.</span>family() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> titleFont<span class="operator">.</span>pointSizeF() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;pt\n&quot;</span>
          <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Smallest font: &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> smallestReadableFont<span class="operator">.</span>family() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> smallestReadableFont<span class="operator">.</span>pointSizeF() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;pt\n&quot;</span>;

      <span class="keyword">return</span> text;
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>showInfo()
  {
      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> screenGeometry <span class="operator">=</span> <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>desktop()<span class="operator">-</span><span class="operator">&gt;</span>screenGeometry(<span class="keyword">this</span>);
      FontInfoDialog <span class="operator">*</span>dialog <span class="operator">=</span> <span class="keyword">new</span> FontInfoDialog(<span class="keyword">this</span>);
      dialog<span class="operator">-</span><span class="operator">&gt;</span>setWindowTitle(tr(<span class="string">&quot;Fonts&quot;</span>));
      dialog<span class="operator">-</span><span class="operator">&gt;</span>setAttribute(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>WA_DeleteOnClose);
      dialog<span class="operator">-</span><span class="operator">&gt;</span>resize(screenGeometry<span class="operator">.</span>width() <span class="operator">/</span> <span class="number">4</span><span class="operator">,</span> screenGeometry<span class="operator">.</span>height() <span class="operator">/</span> <span class="number">4</span>);
      dialog<span class="operator">-</span><span class="operator">&gt;</span>show();
  }

</pre>
</div>
<!-- @@@widgets/charactermap/mainwindow.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
